package com.hdjk.view.activity.investment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hdjk.view.R;
import com.hdjk.view.callback.CallBackListener;
import com.hdjk.view.network.GroupNetWork;
import com.hdjk.view.util.UserTokenUtil;
import com.lst.projectlib.base.BaseActivity;
import com.lst.projectlib.entity.BaseEntity;
import com.lst.projectlib.entity.Msg;

/**
 * Created by sxy on 2017/11/15.
 */

public class ZHDRiskTestReturnActivity extends BaseActivity implements View.OnClickListener {
    private String code;
    // Content View Elements
    private com.lst.projectlib.component.CustomView.TopTitleBar ttb_title_bar;
    private ImageView iv_top;
    private RelativeLayout rel_bg;
    private TextView tv_title;
    private TextView tv_point;
    private Button btn_reset;
    // End Of Content View Elements

    private void bindViews() {
        ttb_title_bar = (com.lst.projectlib.component.CustomView.TopTitleBar) findViewById(R.id.ttb_title_bar);
        iv_top = (ImageView) findViewById(R.id.iv_top);
        rel_bg = (RelativeLayout) findViewById(R.id.rel_bg);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_point = (TextView) findViewById(R.id.tv_point);
        btn_reset = (Button) findViewById(R.id.btn_reset);
    }


    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_zhd_risk_test_return);
        bindViews();
        ttb_title_bar.findViewById(R.id.tvNavBack).setOnClickListener(this);
        ttb_title_bar.findViewById(R.id.tvNavFinish).setOnClickListener(this);
        ((TextView)ttb_title_bar.findViewById(R.id.tvNavFinish)).setText("重新测试");
        btn_reset.setOnClickListener(this);
//        DisplayMetrics dm = new DisplayMetrics();
//        getWindowManager().getDefaultDisplay().getMetrics(dm);
//        ViewGroup.LayoutParams layoutParams=iv_top.getLayoutParams();
//        layoutParams.width=dm.widthPixels;
//        layoutParams.height=(int)((float)(dm.widthPixels)/986*1074);
//        iv_top.setLayoutParams(layoutParams);
    }

    @Override
    protected void initData() {
        String type = getIntent().getStringExtra("type");
        tv_title.setText(type);
        switch (type) {
            case "中度保守型":
                rel_bg.setBackgroundColor(getResources().getColor(R.color.baoshou));
                iv_top.setImageDrawable(getResources().getDrawable(R.drawable.baoshou));
                btn_reset.setBackgroundResource(R.drawable.button_baoshou);
                ttb_title_bar.setBackgroundColor(getResources().getColor(R.color.baoshou));
                tv_title.setTextColor(getResources().getColor(R.color.baoshou_text));
                break;
            case "环球":
                rel_bg.setBackgroundColor(getResources().getColor(R.color.huanqiu));
                iv_top.setImageDrawable(getResources().getDrawable(R.drawable.huanqiu));
                btn_reset.setBackgroundResource(R.drawable.button_huanqiu);
                ttb_title_bar.setBackgroundColor(getResources().getColor(R.color.huanqiu));
                tv_title.setTextColor(getResources().getColor(R.color.huanqiu_text));
                tv_title.setText(type+"型");
                break;
            case "中度进取型":
                rel_bg.setBackgroundColor(getResources().getColor(R.color.zhongdujinqu));
                iv_top.setImageDrawable(getResources().getDrawable(R.drawable.zhongdujinqu));
                btn_reset.setBackgroundResource(R.drawable.button_zhongdujinqu);
                ttb_title_bar.setBackgroundColor(getResources().getColor(R.color.zhongdujinqu));
                tv_title.setTextColor(getResources().getColor(R.color.zhongdujinqu_text));
                break;
            case "进取型":
                rel_bg.setBackgroundColor(getResources().getColor(R.color.jinqu));
                iv_top.setImageDrawable(getResources().getDrawable(R.drawable.jinqu));
                btn_reset.setBackgroundResource(R.drawable.button_jinqu);
                ttb_title_bar.setBackgroundColor(getResources().getColor(R.color.jinqu));
                tv_title.setTextColor(getResources().getColor(R.color.jinqu_text));
                break;
            case "平衡型":
                rel_bg.setBackgroundColor(getResources().getColor(R.color.pingheng));
                iv_top.setImageDrawable(getResources().getDrawable(R.drawable.pingheng));
                btn_reset.setBackgroundResource(R.drawable.button_pingheng);
                ttb_title_bar.setBackgroundColor(getResources().getColor(R.color.pingheng));
                tv_title.setTextColor(getResources().getColor(R.color.pingheng_text));
                break;
            case "夏普":
                rel_bg.setBackgroundColor(getResources().getColor(R.color.xiapu));
                iv_top.setImageDrawable(getResources().getDrawable(R.drawable.xiapu));
                btn_reset.setBackgroundResource(R.drawable.button_xiapu);
                ttb_title_bar.setBackgroundColor(getResources().getColor(R.color.xiapu));
                tv_title.setTextColor(getResources().getColor(R.color.xiapu_text));
                tv_title.setText(type+"型");
                break;
        }
        getRecommendGroup(type);
    }

    private void getRecommendGroup(String assess) {
        GroupNetWork.getRecommendGroup(UserTokenUtil.getToken(this), assess, new CallBackListener() {
            @Override
            public void onCallBackCompleted(Msg msg) {
                if (msg!=null&&msg.getSuccess()){
                    BaseEntity entity= (BaseEntity) msg.getData();
                    if (entity!=null) {
                        code = entity.getId();
                        tv_point.setText(entity.getName());
                    }
                }
            }

            @Override
            public void onCallBackError(Msg msg) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.tvNavBack:
                back();
                break;
            case R.id.tvNavFinish:
                intent = new Intent(ZHDRiskTestReturnActivity.this, ZHDRiskTestActivity.class);
                startActivity(intent);
                back();
                break;
            case R.id.btn_reset:
                intent = new Intent(ZHDRiskTestReturnActivity.this, GroupDetailActivity.class);
                intent.putExtra("code",code);
                startActivity(intent);
                break;
        }
    }
}
